package com.gelsanalyzer.ui.swing.command;

import java.util.*;

import javax.swing.*;

import com.gelsanalyzer.business.*;
import com.gelsanalyzer.business.control.*;
import com.gelsanalyzer.ui.swing.*;

public class CourseNumComboCommand extends JComboBox implements Command {
    // store a reference to the parent container
    CourseEntryPanel courseEntryPanel;
    // more dependencies. this one can probably be refactored out.
    Handler handler;

    public CourseNumComboCommand(CourseEntryPanel courseEntryPanel,
                                 Handler handler) {
        super();
        this.courseEntryPanel = courseEntryPanel;
        this.handler = handler;
        this.addActionListener(handler);
    }

    public void Execute() {
        Object obj = getSelectedItem();
        Course course = null;
        if ( obj instanceof Course ) {
            course = (Course) obj;
        }
        // System.out.println("course=" + course);
        // FIXME: this section of code needs to be refactored out such that we
        // just need to raise an event for the button to handle itself
        courseEntryPanel.getAddCourseButton().setEnabled(true);
        // FIXME: this really needs to be refactored to handle the situtation
        // correctly...
        ((CourseEntryHandler) handler).getCourseEntryFrame()
            .getCourseMgmtMenuBar().getEditAddCourseMenuItem().setEnabled(true);
    }

    public void addCourseNums(List<Course> firePopulateCourses) {
        removeAllItems();

        // Un-comment Line below in case we want to have a blank field
        addItem(null);

        for ( Course course : firePopulateCourses ) {
            addItem(course);
        }
    }
}
